<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<div class="modal inmodal editPage" id="${ firstLowerClassPre }FormPage" role="dialog"
	aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<button class="close" data-dismiss="modal" type="button">×</button>
				<h4 id="modalHeaderMsg" class="modal-title"></h4>
			</div>
			<div class="modal-body">
				<form id="form-edit" class="form-horizontal m-t" ovalidate="novalidate">
					<input type="hidden" id="id" name="id">
					<#list tableConfig.addFields as addField>
					<div class="form-group">
						<label class="col-sm-3 control-label">
							<#if !fieldMap[addField].canNull>*</#if>${fieldMap[addField].viewName}：
						</label>
						<div class="col-sm-6">
						<#if fieldMap[addField].dataBaseProType == 'CLOB' || fieldMap[addField].columnLength gt 128 >
							<textarea id="${fieldMap[addField].proName}" name="${fieldMap[addField].proName}" class="form-control <#if !fieldMap[addField].canEdit>disabled-edit</#if>" <#if !fieldMap[addField].canNull>required</#if> <#if fieldMap[addField].minLength?? && fieldMap[addField].minLength gt 0>minlength="${fieldMap[addField].minLength}"</#if> <#if fieldMap[addField].maxLength??>maxlength="${fieldMap[addField].maxLength?c}"</#if>></textarea>
						<#elseif fieldMap[addField].hasEnum>
							<#if fieldMap[addField].enumList?size ==2 >
							<div class="col-sm-6">
								<div class="radio i-checks">
									<label><input type="radio" value="${fieldMap[addField].enumList[0].value}" class="<#if !fieldMap[addField].canEdit>disabled-edit</#if>" name="${fieldMap[addField].proName}"> <i></i> ${fieldMap[addField].enumList[0].name}</label>
								</div>
							</div>
							<div class="col-sm-6">
								<div class="radio i-checks">
									<label><input type="radio" value="${fieldMap[addField].enumList[1].value}" class="<#if !fieldMap[addField].canEdit>disabled-edit</#if>" name="${fieldMap[addField].proName}"> <i></i> ${fieldMap[addField].enumList[1].name}</label>
								</div>
							</div>
							<#else>
							<select class="form-control <#if !fieldMap[addField].canEdit>disabled-edit</#if>" id="${fieldMap[addField].proName}" name="${fieldMap[addField].proName}">
								<#list fieldMap[addField].enumList as enum>
								<option value="${enum.value}">${enum.name}</option>
								</#list>
							</select>
							</#if>
						<#else>
							<#if fieldMap[addField].proType == 'Integer' || fieldMap[addField].proType == 'Long' >
							<input type="text" id="${fieldMap[addField].proName}" name="${fieldMap[addField].proName}" class="form-control integer <#if !fieldMap[addField].canEdit>disabled-edit</#if>" <#if !fieldMap[addField].canNull>required</#if> <#if fieldMap[addField].minLength?? >min="${fieldMap[addField].minLength}"</#if> <#if fieldMap[addField].maxLength??>max="${fieldMap[addField].maxLength?c}"</#if>/>
							<#elseif fieldMap[addField].proType == 'BigDecimal'>
							<input type="text" id="${fieldMap[addField].proName}" name="${fieldMap[addField].proName}" class="form-control float <#if !fieldMap[addField].canEdit>disabled-edit</#if>" <#if !fieldMap[addField].canNull>required</#if> <#if fieldMap[addField].minLength?? >min="${fieldMap[addField].minLength}"</#if> <#if fieldMap[addField].maxLength??>max="${fieldMap[addField].maxLength?c}"</#if>/>
							<#elseif fieldMap[addField].proType == 'Date'>
                            <input type="text" id="${fieldMap[addField].proName}" name="${fieldMap[addField].proName}" class="form-control layer-date" placeholder="${fieldMap[addField].dateFormat}" data-format="${fieldMap[addField].dateFormat}" <#if !fieldMap[addField].canNull>required</#if>/>
							<#else>
							<input type="text" id="${fieldMap[addField].proName}" name="${fieldMap[addField].proName}" class="form-control <#if !fieldMap[addField].canEdit>disabled-edit</#if>" <#if !fieldMap[addField].canNull>required</#if> <#if fieldMap[addField].minLength?? && fieldMap[addField].minLength gt 0>minlength="${fieldMap[addField].minLength}"</#if> <#if fieldMap[addField].maxLength??>maxlength="${fieldMap[addField].maxLength?c}"</#if>/>
							</#if>
						</#if>
						</div>
					</div>
					</#list>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-white btn-cancel" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary btn-save" onClick="formSubmit();">保存</button>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
	$(function() {
		judgeVerification();
	})

	// 表单提交
	function formSubmit() {
		if (!$('#${ firstLowerClassPre }FormPage #form-edit').valid()){
			return;
		}
		$.ajax({
			type : "POST",
            url: CONTEXT_PATH + "/${moduleName}/${ firstLowerClassPre }/save.do",
			data : $("#${ firstLowerClassPre }FormPage #form-edit").serialize(),
			dataType : "json",
			success : function(data) {
				if (data.success) {
					common_success("保存成功！");
                    retunListPage();// 返回列表
                    refreshTable(${ firstLowerClassPre }BodyId); // 刷新列表
				} else {
					common_error(data.errDesc);
				}
			},
			complete : function() {
			}
		});
	}

	// form表单校验
	function judgeVerification() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $('#${ firstLowerClassPre }FormPage #form-edit').validate({
            rules: {},
            messages: {}
        });
	};

</script>